home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / guile0.4.lcm / share / guile / slib / scheme48.init < prev    next >
Encoding:
Text File  |  2004-01-06  |  8.5 KB  |  283 lines

  1. ;;;"scheme48.init" Initialisation for SLIB for Scheme48    -*-scheme-*-
  2. ;;; Author: Aubrey Jaffer
  3. ;;;
  4. ;;; This code is in the public domain.
  5.  
  6. ;;; If you know the magic incantation to make a "," command available
  7. ;;; as a scheme procedure, you can make a nifty slib function to do
  8. ;;; this (like `slib:dump' in "vscm.init").  But for now, type:
  9. ;;;    make slib48
  10.  
  11. ;;; (software-type) should be set to the generic operating system type.
  12. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported.
  13.  
  14. (define (software-type) 'UNIX)
  15.  
  16. ;;; (scheme-implementation-type) should return the name of the scheme
  17. ;;; implementation loading this file.
  18.  
  19. (define (scheme-implementation-type) 'Scheme48)
  20.  
  21. ;;; (scheme-implementation-home-page) should return a (string) URL
  22. ;;; (Uniform Resource Locator) for this scheme implementation's home
  23. ;;; page; or false if there isn't one.
  24.  
  25. (define (scheme-implementation-home-page)
  26.   "http://www.neci.nj.nec.com/homepages/kelsey.html")
  27.  
  28. ;;; (scheme-implementation-version) should return a string describing
  29. ;;; the version of the scheme implementation loading this file.
  30.  
  31. (define scheme-implementation-version
  32.   (cond ((= -86400 (modulo -2177452800 -86400))
  33.      (display "scheme48-0.36 has been superseded by")
  34.      (newline)
  35.      (display "http://swissnet.ai.mit.edu/ftpdir/s48/scheme48-0.46.tgz")
  36.      (newline)
  37.      (lambda () "0.36"))
  38.     (else (lambda () "0.46"))))
  39.  
  40. ;;; (implementation-vicinity) should be defined to be the pathname of
  41. ;;; the directory where any auxiliary files to your Scheme
  42. ;;; implementation reside.
  43.  
  44. ;;; [ defined from the Makefile ]
  45.  
  46. ;;; (library-vicinity) should be defined to be the pathname of the
  47. ;;; directory where files of Scheme library functions reside.
  48.  
  49. ;;; [ defined from the Makefile ]
  50.  
  51. (define getenv s48-getenv)
  52. (define system s48-system)
  53.  
  54. ;;; (home-vicinity) should return the vicinity of the user's HOME
  55. ;;; directory, the directory which typically contains files which
  56. ;;; customize a computer environment for a user.
  57.  
  58. (define home-vicinity
  59.   (let ((home-path (getenv "HOME")))
  60.     (lambda () home-path)))
  61.  
  62. ;;; *FEATURES* should be set to a list of symbols describing features
  63. ;;; of this implementation.  See Template.scm for the list of feature
  64. ;;; names.
  65.  
  66. (define *features*
  67.       '(
  68.     source                ;can load scheme source files
  69.                     ;(slib:load-source "filename")
  70. ;    compiled            ;can load compiled files
  71.                     ;(slib:load-compiled "filename")
  72.     rev4-report            ;conforms to
  73.     ieee-p1178            ;conforms to
  74.     rev4-optional-procedures
  75.     multiarg/and-
  76.     multiarg-apply
  77.     rationalize
  78.     delay                ;has delay and force
  79.     with-file
  80.     char-ready?            ;has
  81.     eval                ;proposed 2-argument eval
  82.     values                ;proposed multiple values
  83.     dynamic-wind            ;proposed dynamic-wind
  84.     full-continuation        ;can return multiple times
  85.     macro                ;R4RS appendix's DEFINE-SYNTAX
  86.     system                ;posix (system <string>)
  87.     getenv                ;posix (getenv <string>)
  88.     ))
  89.  
  90. ;;; (OUTPUT-PORT-WIDTH <port>)
  91. (define (output-port-width . arg) 79)
  92.  
  93. ;;; (OUTPUT-PORT-HEIGHT <port>)
  94. (define (output-port-height . arg) 24)
  95.  
  96. ;;; (CURRENT-ERROR-PORT)
  97. (define current-error-port s48-current-error-port)
  98.  
  99. ;;; (TMPNAM) makes a temporary file name.
  100. (define tmpnam
  101.   (let ((cntr 100))
  102.     (lambda () (set! cntr (+ 1 cntr))
  103.         (let ((tmp (string-append "slib_" (number->string cntr))))
  104.           (if (file-exists? tmp) (tmpnam) tmp)))))
  105.  
  106. ;;; (FILE-EXISTS? <string>)
  107. (define (file-exists? f)
  108.   (call-with-current-continuation
  109.    (lambda (k)
  110.      (s48-with-handler
  111.       (lambda (condition decline)
  112.     (k #f))
  113.       (lambda ()
  114.     (close-input-port (open-input-file f))
  115.     #t)))))
  116.  
  117. ;;; (DELETE-FILE <string>)
  118. (define (delete-file file-name)
  119.   (s48-system (string-append "rm " file-name)))
  120.  
  121. ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
  122. ;;; use this definition if your system doesn't have such a procedure.
  123. (define (force-output . arg)
  124.   (s48-force-output
  125.    (if (null? arg) (current-output-port) (car arg))))
  126.  
  127. ;;; "rationalize" adjunct procedures.
  128. (define (find-ratio x e)
  129.   (let ((rat (rationalize x e)))
  130.     (list (numerator rat) (denominator rat))))
  131. (define (find-ratio-between x y)
  132.   (find-ratio (/ (+ x y) 2) (/ (- x y) 2)))
  133.  
  134. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  135. ;;; be returned by CHAR->INTEGER.
  136. (define integer->char s48-ascii->char)
  137. (define char->integer
  138.   (let ((char->integer char->integer)
  139.     (code0 (char->integer (integer->char 0))))
  140.     (lambda (char) (- (char->integer char) code0))))
  141. (define char-code-limit 256)
  142.  
  143. ;;; Workaround MODULO bug
  144. (define modulo
  145.   (let ((modulo modulo))
  146.     (lambda (n1 n2)
  147.       (let ((ans (modulo n1 n2)))
  148.     (if (= ans n2) (- ans ans) ans)))))
  149.  
  150. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  151. (define most-positive-fixnum #x1FFFFFFF)
  152.  
  153. ;;; Return argument
  154. (define (identity x) x)
  155.  
  156. ;;; SLIB:EVAL is single argument eval using the top-level (user) environment.
  157. (define slib:eval
  158.   (let ((eval eval)
  159.     (interaction-environment interaction-environment))
  160.     (lambda (form)
  161.       (eval form (interaction-environment)))))
  162.  
  163. ;;; If your implementation provides R4RS macros:
  164. (define macro:eval slib:eval)
  165. (define (macro:load <pathname>)
  166.   (if (not (file-exists? <pathname>))
  167.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  168.   (load <pathname>))
  169.  
  170. (define *defmacros*
  171.   (list (cons 'defmacro
  172.           (lambda (name parms . body)
  173.         `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
  174.                       *defmacros*))))))
  175. (define (defmacro? m) (and (assq m *defmacros*) #t))
  176.  
  177. (define (macroexpand-1 e)
  178.   (if (pair? e) (let ((a (car e)))
  179.           (cond ((symbol? a) (set! a (assq a *defmacros*))
  180.                      (if a (apply (cdr a) (cdr e)) e))
  181.             (else e)))
  182.       e))
  183.  
  184. (define (macroexpand e)
  185.   (if (pair? e) (let ((a (car e)))
  186.           (cond ((symbol? a)
  187.              (set! a (assq a *defmacros*))
  188.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  189.             (else e)))
  190.       e))
  191.  
  192. (define gentemp
  193.   (let ((*gensym-counter* -1))
  194.     (lambda ()
  195.       (set! *gensym-counter* (+ *gensym-counter* 1))
  196.       (string->symbol
  197.        (string-append "slib:G" (number->string *gensym-counter*))))))
  198.  
  199. (define base:eval slib:eval)
  200. (define (defmacro:eval x) (base:eval (defmacro:expand* x)))
  201. (define (defmacro:expand* x)
  202.   (require 'defmacroexpand) (apply defmacro:expand* x '()))
  203.  
  204. (define (defmacro:load <pathname>)
  205.   (slib:eval-load <pathname> defmacro:eval))
  206.  
  207. (define (slib:eval-load <pathname> evl)
  208.   (if (not (file-exists? <pathname>))
  209.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  210.   (call-with-input-file <pathname>
  211.     (lambda (port)
  212.       (let ((old-load-pathname *load-pathname*))
  213.     (set! *load-pathname* <pathname>)
  214.     (do ((o (read port) (read port)))
  215.         ((eof-object? o))
  216.       (evl o))
  217.     (set! *load-pathname* old-load-pathname)))))
  218.  
  219. (define slib:warn
  220.   (lambda args
  221.     (let ((cep (current-error-port)))
  222.       (if (provided? 'trace) (print-call-stack cep))
  223.       (display "Warn: " cep)
  224.       (for-each (lambda (x) (display x cep)) args))))
  225.  
  226. ;;; define an error procedure for the library
  227. (define (slib:error . args)
  228.   (if (provided? 'trace) (print-call-stack (current-error-port)))
  229.   (apply s48-error args))
  230.  
  231. ;;; define these as appropriate for your system.
  232. (define slib:tab (s48-ascii->char 9))
  233. (define slib:form-feed (s48-ascii->char 12))
  234.  
  235. ;;; Support for older versions of Scheme.  Not enough code for its own file.
  236. (define (last-pair l) (if (pair? (cdr l)) (last-pair (cdr l)) l))
  237. (define t #t)
  238. (define nil #f)
  239.  
  240. ;;; Define these if your implementation's syntax can support them and if
  241. ;;; they are not already defined.
  242.  
  243. (define (1+ n) (+ n 1))
  244. (define (-1+ n) (+ n -1))
  245. ;(define 1- -1+)
  246.  
  247. (define in-vicinity string-append)
  248.  
  249. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  250. ;;; return if exitting not supported.
  251. (define slib:exit (lambda args #f))
  252.  
  253. ;;; Here for backward compatability
  254. (define scheme-file-suffix
  255.   (case (software-type)
  256.     ((NOSVE) (lambda () "_scm"))
  257.     (else (lambda () ".scm"))))
  258.  
  259. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  260. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  261.  
  262. (define (slib:load-source f) (load (string-append f (scheme-file-suffix))))
  263.  
  264. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  265. ;;; by compiling "foo.scm" if this implementation can compile files.
  266. ;;; See feature 'COMPILED.
  267.  
  268. (define slib:load-compiled load)
  269.  
  270. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  271.  
  272. (define slib:load slib:load-source)
  273.  
  274. ;;; Scheme48 complains that these are not defined (even though they
  275. ;;; won't be called until they are).
  276. (define synclo:load #f)
  277. (define syncase:load #f)
  278. (define macwork:load #f)
  279. (define transcript-on #f)
  280. (define transcript-off #f)
  281.  
  282. (slib:load (in-vicinity (library-vicinity) "require"))
  283.